package com.nulldev.util.web.nTube.pages.misc;

import java.util.Map;

import com.nulldev.util.JVM.JVM;

public class BrowserSpecificWorkarounds implements IBrowserSpecificWorkarounds {

	private static boolean hasEnabled(final String ua, final int flag) {
		for (final Map.Entry<String, Integer> entries : WORKAROUNDS.entrySet()) {
			if (ua.contains(entries.getKey()))
				return (entries.getValue() & flag) != 0;
		}
		return false;
	}

	public static boolean forceDisableSubitlteStyling(final String userAgent) {
		return hasEnabled(userAgent, BROWSER_WORKAROUND_DISABLE_STYLING);
	}

	public static boolean forceDisableSubitltePositioning(final String userAgent) {
		return hasEnabled(userAgent, BROWSER_WORKAROUND_DISABLE_POSITIONING);
	}

	public static boolean requiresShorterTimestampPrecision(final String userAgent) {
		return hasEnabled(userAgent, BROWSER_WORKAROUND_REQUIRE_LESS_TIMESTAMP_PRECISION);
	}

	public static void main(final String[] args) {
		JVM.println("======");
		{
			final String ua = "Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko";
			JVM.println("forceDisableSubitlteStyling: " + forceDisableSubitlteStyling(ua));
			JVM.println("forceDisableSubitltePositioning: " + forceDisableSubitltePositioning(ua));
			JVM.println("requiresShorterTimestampPrecision: " + requiresShorterTimestampPrecision(ua));
		}
		JVM.println("======");
		{
			final String ua = "Mozilla/5.0 (BB10; Kbd) AppleWebKit/537.35+ (KHTML, like Gecko) Version/10.3.3.2163 Mobile Safari/537.35+";
			JVM.println("forceDisableSubitlteStyling: " + forceDisableSubitlteStyling(ua));
			JVM.println("forceDisableSubitltePositioning: " + forceDisableSubitltePositioning(ua));
			JVM.println("requiresShorterTimestampPrecision: " + requiresShorterTimestampPrecision(ua));
		}
		JVM.println("======");
	}
}
